﻿namespace WriterStars.Data.Repository
{
    using System.Linq;
    using WriterStars.Model;

    public class LikeRepository : GenericRepository<Like>, ILikesRepository
    {
        public LikeRepository()
            :base(new WriterStarsDbContext())
        {
        }

        public LikeRepository(IWriterStarsDbContext db)
            :base(db)
        {
        }

        public IQueryable<Like> GetByBookId(int id)
        {
            return this.db.Likes.Where(x => x.BookId == id);
        }

        public IQueryable<Like> GetByUserId(string id)
        {
            return this.db.Likes.Where(x => x.UserId == id);
        }

        public Like GetUserBookLike(string userId, int bookId)
        {
            var result = this.db.Likes.FirstOrDefault(x => x.BookId == bookId && x.UserId == userId);
            return result;
        }
    }
}
